﻿using System.Collections.Generic;
using System.Linq;

namespace OdaOperation.Core.Parameters
{
    public class ParameterSet : List<ParameterItem>
    {
        public ParameterSet()
        {
        }

        public ParameterSet(List<ParameterItem> value)
        {
            foreach (ParameterItem item in value)
            {
                Add(item);
            }
        }

        public object GetValue(string name)
        {
            ParameterItem parameterItem = this.FirstOrDefault((ParameterItem x) => x.Name == name);
            if (parameterItem != null)
            {
                return parameterItem.Value;
            }

            return this.FirstOrDefault((ParameterItem x) => name.StartsWith(x.Name + "_"))?.Value;
        }
    }
}